package com.fsm.demo.controller;

import com.fsm.demo.entity.dto.droolsDto.OrderDiscount;
import com.fsm.demo.entity.dto.droolsDto.OrderRequest;
import com.fsm.demo.service.DroolsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "Drools规则引擎测试")
@RequestMapping("/drools")
public class DroolsController {

    @Autowired
    private DroolsService oDroolsService;

    /**
     * 入参测试
     * {
     *     "customerNumber":"123456",
     *     "age":20,
     *     "amount":20000,
     *     "customerType":"LOYAL"
     * }
     * 返回结果
     * {
     *   "discount": 10
     * }
     * @param orderRequest
     * @return
     */
    @PostMapping("testDrools")
    @Operation(summary="Drools规则引擎测试",description="Drools规则引擎测试")
    public ResponseEntity<OrderDiscount> getDiscount(@RequestBody OrderRequest orderRequest) {
        OrderDiscount discount = oDroolsService.getDiscount(orderRequest);
        return new ResponseEntity<>(discount, HttpStatus.OK);
    }

}
